<div>
    <ul class="breadcrumb">
        <li>
            <a href="<?php echo site_url('m-admin')?>">管理首页</a> <span class="divider">/</span>
        </li>
        <li>
            <a href="<?php echo site_url('m-admin')?>">图片管理</a> <span class="divider">/</span>
        </li>
        <li>
            <a href="#">添加图片</a>
        </li>
    </ul>
</div>

<div class="row-fluid">
    <form class="form-horizontal" method="post"
          id="save_form"
          enctype="application/x-www-form-urlencoded"
          action="#">
        <fieldset>
            <legend>添加图片
            </legend>
            <div id="form_msg" class="alert" style="display: none;">
                <button type="button" class="close" onclick="$('#form_msg').hide();">×</button>
                <p></p>
            </div>

            <div class="control-group">
                <label class="control-label">
                    图片分类
                </label>
                <div class="controls">
                    <select id="image_type" name="image_type">
                        <option value="<?php echo $type;?>"><?php echo $image_type[$type];?></option>
<!--                        --><?php //foreach ($image_types as $key => $image_typ):?>
<!--                            <option value="--><?php //echo $key;?><!--">-->
<!--                                --><?php //echo $image_typ;?>
<!--                            </option>-->
<!--                        --><?php //endforeach;?>
                        <span class="image_notice notice_<?php echo $type;?>"
                              style="">
                            <?php echo $image_type[$type];?>
                        </span>
                    </select>
                </div>
            </div>

            <div class="control-group">
                <label class="control-label">
                    <span id="flash_upload_select_picture"></span>
                    <input type="hidden" name="upnum" id="up_num" value="0" />
                </label>
                <div class="controls">
                    <div id="flash_upload_progress"
                         class="span5"
                         style="border:solid 1px #CCC;height:220px; overflow: scroll;">
                    </div>
                </div>
            </div>


            <div class="form-actions">
                <input type="button" id="btnUpload" class="btn btn-primary"
                       value="开始上传"
                       onClick='start_upload()' disabled="disabled"/>
                <input type="hidden" name="id" value="<?php echo $id;?>" />
<!--                <input type="hidden" name="mark" value="--><?php //echo $mark;?><!--"/>-->
                <input type="hidden" name="action" value="save" />
            </div>
        </fieldset>
    </form>
</div>
<link href="/static/ui/swfupload/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/static/ui/swfupload/swfupload.js"></script>
<script type="text/javascript" src="/static/ui/swfupload/swfupload.queue.js"></script>
<script type="text/javascript" src="/static/ui/swfupload/fileprogress.js"></script>
<script type="text/javascript" src="/static/ui/swfupload/handlers.js"></script>
<script>
    var swfu;
    var upload_image_type = '';
    window.onload = function() {
        var settings = {

            // Backend Settings
            upload_url: "<?php echo site_url('m-admin/image/upload')?>",	// Relative to the SWF file (or you can use absolute paths)
            post_params: {},

            // File Upload Settings
            file_size_limit : "2048",	// 2MB
            file_types : "*.jpg;*.gif;*.png;*.bmp",
            file_types_description : "All Files",
            file_upload_limit	:	"10",	//最多上传30张
            file_queue_limit	:	"10",	//最多选择30张

            // Event Handler Settings (all my handlers are in the Handler.js file)
            file_dialog_start_handler:		fileDialogStart,
            file_queued_handler:			fileQueued,
            file_queue_error_handler :		fileQueueError,
            file_dialog_complete_handler :	fileDialogComplete,
            upload_start_handler :			uploadStart,
            upload_progress_handler :		uploadProgress,
            upload_error_handler :			uploadError,
            upload_success_handler :		uploadSuccess,
            upload_complete_handler :		uploadComplete,
            queue_complete_handler :		queueComplete,

            // Button Settings
            button_image_url : "/static/ui/swfupload/add_photo.png",	// Relative to the SWF file
            button_placeholder_id : "flash_upload_select_picture",
            button_width:	74,
            button_height:	25,

            // Flash Settings
            flash_url : "/static/ui/swfupload/swfupload.swf",

            custom_settings : {
                progressTarget : "flash_upload_progress"
                //cancelButtonId : "btnCancel1"
            },
            debug: false
        };

        swfu = new SWFUpload(settings);

        $('#image_type').change(function () {
            upload_image_type = this.value;

            var show_notice = 'notice_';

            if (upload_image_type == '') {
                show_notice += 'none';
            } else {
                show_notice += upload_image_type;
            }

            $('.image_notice').hide();
            $('.' + show_notice).show();
        });
    };

    //开始上传
    function start_upload(){
       /* if (upload_image_type == '') {
            error_msg_show('form_msg', '请选择图片分类');
            return false;
        }*/
        //alert(<?php echo $id;?>);
        var type = "<?php echo $type;?>";
        swfu.addPostParam('id', <?php echo $id;?>);
        swfu.addPostParam('type', type);
        swfu.startUpload();
        $('#btnUpload').prop('disabled', true).val("上传中...");
    }

    //单图上传回调函数,返回上传完成文件的信息
    function ts_upload_success(serverData){
        var data	=	eval('('+serverData+')');
        if(data.status==true){
            return true;
        }else{
            alert(data.msg);
            return false;
        }
    }

    //当文件队列有文件时
    function enableUploadButton(file){
        $('#btnUpload').attr('disabled',false).val("开始上传");
    }
    //全部上传完成
    function queueComplete(numFilesUploaded) {
        return false;
        $("#up_num").val(numFilesUploaded);
        $("#save_form").resetForm();
    }
</script>